/*
 * @Author: szx
 * @Date: 2022-03-16 13:35:19
 * @LastEditTime: 2022-03-16 13:43:58
 * @Description:
 * @FilePath: \leetcode\300-399\376\376_2.js
 */
/**
 * @param {number[]} nums
 * @return {number}
 */
var wiggleMaxLength = function (nums) {
    let res = 0;
    let preDiff = 0;
    for (let i = 0; i < nums.length - 1; i++) {
        const diff = nums[i + 1] - nums[i];
        if ((preDiff <= 0 && diff > 0) || (preDiff >= 0 && diff < 0)) {
            // console.log(nums[i], i);
            res++;
            preDiff = diff;
        }
    }
    return res + 1;
};
console.log(wiggleMaxLength([1, 2, 3, 4, 5, 6, 7, 8, 9]));
console.log(wiggleMaxLength([1, 17, 5, 10, 13, 15, 10, 5, 16, 8]));
console.log(wiggleMaxLength([1, 7, 4, 9, 2, 5]));
console.log(wiggleMaxLength([2, 2, 3, 4, 4, 3]));
